package cn.mengfly.algorithm.collection.queue;

import cn.mengfly.algorithm.sort.SortUtil;

/**
 * @author Mengfly
 * @date 2021/6/2 23:48
 */
public class HeapMinPriorityQueue<Key extends Comparable<? super Key>> implements MinPriorityQueue<Key> {

    private final HeapPriorityHelper<Key> delegate;

    public HeapMinPriorityQueue(int max) {
        delegate = new HeapPriorityHelper<>(max, (key, key2) -> SortUtil.less(key2, key));
    }

    @Override
    public void insert(Key v) {
        delegate.insert(v);
    }

    @Override
    public Key min() {
        return delegate.priorityValue();
    }

    @Override
    public Key delMin() {
        return delegate.delPriorityValue();
    }

    @Override
    public boolean isEmpty() {
        return delegate.size() == 0;
    }

    @Override
    public int size() {
        return delegate.size();
    }
}
